<%@ page import="com.silverhaze.web.WebConstants" %>
<%@ page import="com.silverhaze.web.data.wot.presentation.WoTPlayerStatistics" %>
<%@ page import="com.silverhaze.web.data.wot.presentation.WoTTankStatistics" %>
<%@ page import="com.silverhaze.web.util.DateUtil" %>
<%@ page import="com.silverhaze.web.util.EntityManageUtil" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%

    java.util.Date currentDate = new java.util.Date();
    java.util.Date previousWeekDate = new java.util.Date(currentDate.getTime() - 7 * DateUtil.MSECS_IN_DAY);

    Date currentSQLDate = new Date(currentDate.getTime());
    Date previousSQLDate = new Date(currentDate.getTime() - 1 * DateUtil.MSECS_IN_DAY);
    Date previousWeekSQLDate = new Date(currentDate.getTime() - 7 * DateUtil.MSECS_IN_DAY);

    List<WoTTankStatistics> tankStatistics = EntityManageUtil.loadTankStatistics(previousSQLDate, currentSQLDate);
    List<WoTPlayerStatistics> playerStatistics = EntityManageUtil.loadPlayersStatistics(previousSQLDate, currentSQLDate);

    List<WoTTankStatistics> tankStatisticsWeek = EntityManageUtil.loadTankStatistics(previousWeekSQLDate, currentSQLDate);
    List<WoTPlayerStatistics> playerStatisticsWeek = EntityManageUtil.loadPlayersStatistics(previousWeekSQLDate, currentSQLDate);
%>


<!DOCTYPE html>
<html>
<head>
    <title>SilverHaze.Info :: World Of Tanks - Статистика</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/table.sorter.js"></script>
    <link href="style/style.css" rel="stylesheet">
</head>
<body>
<img src="img/wot_sml.png" alt="World Of Tanks"/>

<h1>Статистика за <%=WebConstants.DATE_FORMAT.format(currentDate)%>
</h1>

<h2>Игроки</h2>

<div class="sorting">Сортировать:&nbsp;&nbsp;
    <a href="#" onclick="player_sorter.work(1)" class="sorting_link">бои</a>&nbsp;&nbsp;
    <a href="#" onclick="player_sorter.work(2)" class="sorting_link">победы</a>&nbsp;&nbsp;
    <a href="#" onclick="player_sorter.work(3)" class="sorting_link">поражения</a>&nbsp;&nbsp;
    <a href="#" onclick="player_sorter.work(4)" class="sorting_link">опыт</a></div>
<table class="sortable" id="player_sorter">
    <tr>
        <th>Игрок</th>
        <th>Бои</th>
        <th>Побед</th>
        <th>Поражений</th>
        <th>Ничьи</th>
        <th>Опыт</th>
        <th>Нанес повреждений</th>
        <th>Уничтожил</th>
        <th>Обнаружил</th>
        <th>Очки захвата базы</th>
        <th>Очки защиты базы</th>
    </tr>
    <%
        for (WoTPlayerStatistics playerStat : playerStatistics) {
    %>
    <tr>
        <td><a href="player.jsp?name=<%=playerStat.getPlayer()%>"><%=playerStat.getPlayer()%>
        </a>
        </td>
        <td><%=playerStat.getBattles()%>
        </td>
        <td><%=playerStat.getWins()%> (<%=WebConstants.DOUBLE_FORMAT.format(playerStat.getWinPercent())%>%)
        </td>
        <td><%=playerStat.getLooses()%>  (<%=WebConstants.DOUBLE_FORMAT.format(playerStat.getLoosePercent())%>%)
        </td>
        <td><%=playerStat.getDraws()%>  (<%=WebConstants.DOUBLE_FORMAT.format(playerStat.getDrawPercent())%>%)
        </td>
        <td><%=playerStat.getTotalExp()%>
        </td>
        <td><%=playerStat.getDamagePoints()%>
        </td>
        <td><%=playerStat.getKilled()%>
        </td>
        <td><%=playerStat.getDiscovered()%>
        </td>
        <td><%=playerStat.getBaseAttackPoints()%>
        </td>
        <td><%=playerStat.getBaseDefencePoints()%>
        </td>
    </tr>
    <%
        }
    %>
</table>

<br>

<h2>Техника</h2>

<div class="sorting">Сортировать:&nbsp;&nbsp;
    <a href="#" onclick="tank_sorter.work(1)" class="sorting_link">бои</a>&nbsp;&nbsp;
    <a href="#" onclick="tank_sorter.work(2)" class="sorting_link">победы</a>&nbsp;&nbsp;
</div>
<table class="sortable" id="tank_sorter">
    <tr>
        <th>Модель</th>
        <th>Бои</th>
        <th>Побед</th>
    </tr>
    <%
        for (WoTTankStatistics tankStat : tankStatistics) {
            if (tankStat.getTank().contains("M3 Stuart")) {
                continue;
            }
    %>
    <tr>
        <td><%=tankStat.getTankImage() != null ? "<img src=\"" + tankStat.getTankImage() + "\">" : ""%><%=tankStat.getTank()%>
        </td>
        <td><%=tankStat.getBattles()%>
        </td>
        <td><%=tankStat.getWins()%>
        </td>
    </tr>
    <%
        }
    %>
</table>

<br>

<h1>Статистика за последние 7 дней [<%=WebConstants.DATE_FORMAT.format(previousWeekDate)%>
    - <%=WebConstants.DATE_FORMAT.format(currentDate)%>]</h1>

<h2>Игроки</h2>

<div class="sorting">Сортировать:&nbsp;&nbsp;
    <a href="#" onclick="player_sorter_week.work(1)" class="sorting_link">бои</a>&nbsp;&nbsp;
    <a href="#" onclick="player_sorter_week.work(2)" class="sorting_link">победы</a>&nbsp;&nbsp;
    <a href="#" onclick="player_sorter_week.work(3)" class="sorting_link">поражения</a>&nbsp;&nbsp;
    <a href="#" onclick="player_sorter_week.work(4)" class="sorting_link">опыт</a></div>
<table class="sortable" id="player_sorter_week">
    <tr>
        <th>Игрок</th>
        <th>Бои</th>
        <th>Побед</th>
        <th>Поражений</th>
        <th>Ничьи</th>
        <th>Опыт</th>
        <th>Нанес повреждений</th>
        <th>Уничтожил</th>
        <th>Обнаружил</th>
        <th>Очки захвата базы</th>
        <th>Очки защиты базы</th>
    </tr>
    <%
        for (WoTPlayerStatistics playerStat : playerStatisticsWeek) {
    %>
    <tr>
        <td><a href="player.jsp?name=<%=playerStat.getPlayer()%>"><%=playerStat.getPlayer()%>
        </a>
        </td>
        <td><%=playerStat.getBattles()%>
        </td>
        <td><%=playerStat.getWins()%> (<%=WebConstants.DOUBLE_FORMAT.format(playerStat.getWinPercent())%>%)
        </td>
        <td><%=playerStat.getLooses()%>  (<%=WebConstants.DOUBLE_FORMAT.format(playerStat.getLoosePercent())%>%)
        </td>
        <td><%=playerStat.getDraws()%>  (<%=WebConstants.DOUBLE_FORMAT.format(playerStat.getDrawPercent())%>%)
        </td>
        <td><%=playerStat.getTotalExp()%>
        </td>
        <td><%=playerStat.getDamagePoints()%>
        </td>
        <td><%=playerStat.getKilled()%>
        </td>
        <td><%=playerStat.getDiscovered()%>
        </td>
        <td><%=playerStat.getBaseAttackPoints()%>
        </td>
        <td><%=playerStat.getBaseDefencePoints()%>
        </td>
    </tr>
    <%
        }
    %>
</table>

<br>

<h2>Техника</h2>

<div class="sorting">Сортировать:&nbsp;&nbsp;
    <a href="#" onclick="tank_sorter_week.work(1)" class="sorting_link">бои</a>&nbsp;&nbsp;
    <a href="#" onclick="tank_sorter_week.work(2)" class="sorting_link">победы</a>&nbsp;&nbsp;
</div>
<table class="sortable" id="tank_sorter_week">
    <tr>
        <th>Модель</th>
        <th>Бои</th>
        <th>Побед</th>
    </tr>
    <%
        for (WoTTankStatistics tankStat : tankStatisticsWeek) {
            if (tankStat.getTank().contains("M3 Stuart")) {
                continue;
            }
    %>
    <tr>
        <td><%=tankStat.getTankImage() != null ? "<img src=\"" + tankStat.getTankImage() + "\">" : ""%><%=tankStat.getTank()%>
        </td>
        <td><%=tankStat.getBattles()%>
        </td>
        <td><%=tankStat.getWins()%>
        </td>
    </tr>
    <%
        }
    %>
</table>

<div class="copyright">&copy; Иван Бабанин (SilverHaze), 2012 г. <a href="">babanin@gmail.com</a></div>

<script type="text/javascript">
    var player_sorter = new Table.sorter("player_sorter");
    player_sorter.init("player_sorter");

    var tank_sorter = new Table.sorter("tank_sorter");
    tank_sorter.init("tank_sorter");

    var player_sorter_week = new Table.sorter("player_sorter_week");
    player_sorter_week.init("player_sorter_week");

    var tank_sorter_week = new Table.sorter("tank_sorter_week");
    tank_sorter_week.init("tank_sorter_week");
</script>

</body>
</html>